package models.venue.coach;

import goods.Goods;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by hanbin on 17/5/4.
 */
public class CoachesVO {

    public Double allPrice;

    public Integer allSize;

    public List<CoachVO> coachVOList;

    public static CoachesVO createOrUpdateShopCartVO2(String goodsId) {
        List<CoachVO> coachVOList = new ArrayList<>();
        CoachesVO coachesVO = new CoachesVO();
        Double sPrice = 0d; // 总价

        String[] goodArr = goodsId.split(",");
        for (String good : goodArr){
            CoachVO coachVO = new CoachVO();

            Goods goods = Goods.getGoodsById(Long.valueOf(good));
            String name = goods.name;
            name = name.split("_")[2];
            coachVO.beginAtStr = name.substring(0,4)
                    + "." + name.substring(4,6)
                    + "." + name.substring(6,8)
                    + " " + name.substring(8,10)
                    + ":" + name.substring(10,12);

            coachVO.endAtStr = name.substring(0,4)
                    + "." + name.substring(4,6)
                    + "." + name.substring(6,8)
                    + " " + name.substring(12,14)
                    + ":" + name.substring(14);
            coachVO.price = new BigDecimal(goods.salePrice);

            sPrice += goods.salePrice;

            coachVO.goodsId = goods.id;
            coachVO.img = goods.img;

            Coach coach = Coach.findById(goods.serialId);

            coachVO.coachName = coach.coachName;

            coachVOList.add(coachVO);
        }

        // 订单总金额  商品金额综合
        coachesVO.allPrice = sPrice == null ? 0d : sPrice;
        coachesVO.allSize = coachVOList.size();
        coachesVO.coachVOList = coachVOList;

        return coachesVO;
    }

}
